package serverdata;

import java.io.PrintWriter;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONException;
import org.json.JSONObject;

import com.subway.babynote.syncdata.PostParam;
import com.subway.babynote.syncdata.StringUtil;



public class httpreqhandler {

	public static JSONObject readInput(HttpServletRequest req)
	{
		try
		{
		 String param = req.getParameter(PostParam.user_auth_info_Param.record);		 		 
		 JSONObject jsono = new JSONObject(param);		 
		 return jsono;
		}
		catch (JSONException e) {
			// TODO Auto-generated catch block
			System.out.println("JSON error for FeedSync doPost:" + e.getMessage());
			e.printStackTrace();			
			return null;
		}
		catch (Exception e) {
		 System.out.println("FeedSync doPost error:" + e.getMessage());
	      e.printStackTrace();
	      return null;
	    }
		
	}
	public static void writeOutput(JSONObject jsono, HttpServletResponse response)
	{
		try
		{
			response.setCharacterEncoding("UTF-8");
			response.setContentType("text/html;charset=UTF-8");
			PrintWriter writer = response.getWriter();
			String outstr = jsono.toString();
			//String str = new String(outstr.getBytes("UTF-8"),"UTF-8");
			if(outstr!=null)
				writer.print(outstr);			 
			 writer.close();
		}
		catch (Exception e) {
		 System.out.println("FeedSync doPost error:" + e.getMessage());
	      e.printStackTrace();
	      
	    }
	}
}
